{% extends "public/base.html" %}
{% load nm %}
{% load js %}

{% block head_resources %}
  {{block.super}}
  {% jsinclude "tables,jqplot,sparkline" %}
  <style type="text/css">
  #progstats {
      font-size: small;
  }
  #progstats tbody {
      white-space: nowrap;
  }
  </style>
{% endblock %}

{% block head %}
{{block.super}}
<script type="text/javascript">
$(function() {
    var bystatus = $("#bystatus");
    var byprogress = $("#byprogress");

    $("table.tablesorter").tablesorter({
        textExtraction: function(node) {
            val = node.getAttribute("val");
            if (val == null)
                val = node.textContent || node.innerText;
            return val;
        },
    });

    $.jqplot('bystatus_graph', [{{status_table_json|safe}}], {
        title: "People by status",
        seriesDefaults: {
            renderer: $.jqplot.PieRenderer,
            rendererOptions: {
                sliceMargin: 4,
                dataLabels: "label",
                showDataLabels: true,
            },
        },
        legend: {
            show: false,
        }
    });

    $.jqplot('byprogress_graph', [{{progress_table_json|safe}}], {
        title: "Processes by progress",
        seriesDefaults: {
            renderer: $.jqplot.PieRenderer,
            rendererOptions: {
                sliceMargin: 4,
                dataLabels: "label",
                showDataLabels: true,
            },
        },
        legend: {
            show: false,
        }
    });

    $(".mbox_sparkline").sparkline("html", {
      type: "bar",
      barColor: "#005382",
      negBarColor: "#823000",
      chartRangeMin: -30,
      chartRangeMax: 30
    });
});
</script>
{% endblock %}

{% block breadcrumbs %}{{block.super}} / <a href="{% url 'public_stats' %}">stats</a>{% endblock %}

{% block relatedpages %}
<a href="{% url 'public_stats_latest' %}">latest events</a>
<a href="http://molly.corsac.net/~corsac/debian/nm/">historical graphs</a>
{{block.super}}
{% endblock %}

{% block content %}

<h1>Debian New Member - Statistics</h2>

<h2>People by status</h2>

<div style="float: right; width: 400px; height: 400px;" id="bystatus_graph"></div>

<table id="bystatus" class="tablesorter">
<thead>
    <tr><th>Status</th><th>Count</th></tr>
</thead>
<tbody>
    {% for st, count in status_table %}
    <tr>
        <td val="{{st|seq_status}}">{{st|desc_status}}</td>
        <td>{{count}}</td>
    </tr>
    {% endfor %}
</tbody>
</table>

<h2 style="clear: both">Processes by progress</h2>

<div style="float: right; width: 400px; height: 400px;" id="byprogress_graph"></div>

<table id="byprogress" class="tablesorter">
<thead>
    <tr><th>Progress</th><th>Count</th></tr>
</thead>
<tbody>
    {% for p, count in progress_table %}
    <tr>
        <td val="{{p|seq_progress}}">{{p|desc_progress}}</td>
        <td>{{count}}</td>
    </tr>
    {% endfor %}
</tbody>
</table>

<h2 style="clear: both">Active processes</h2>

<table class="tablesorter" id="progstats">
    <thead>
    <tr>
        <th>Applicant</th>
        <th>Uid</th>
        <th>For</th>
        <th>Manager</th>
        <th>Progr</th>
        <th>Adv</th>
        <th>Started</th>
        <th>Last log</th>
        <th>Total days</th>
        <th>AM days</th>
        <th>AM hold days</th>
        <th>Last AM days</th>
        <th>Last AM hold days</th>
        <th>Mbox age</th>
        {% if visitor.is_am %}
        <th>Activity</th>
        <th>Last log entry</th>
        {% endif %}
    </tr>
    </thead>
    <tbody>
        {% for p in active_processes %}
        <tr>
            <td><a href="{{ p.get_absolute_url }}">{{p.person.fullname}}</a></td>
            <td><a href="{{ p.get_absolute_url }}">{{p.person.uid}}</a></td>
            <td val="{{ p.applying_for|seq_status }}">{{p.applying_for|sdesc_status}}</td>
            <td>
                {% if p.manager %}
                <a href="{{ p.manager.get_absolute_url }}">{{p.manager.person.uid}}</a>
                {% endif %}
            </td>
            <td val="{{ p.progress|seq_progress }}"><a href="{{ p.get_absolute_url }}">{{p.progress|sdesc_progress}}</a></td>
            <td>
                {% for a in p.advocates.all %}
                <a href="{{ a.get_absolute_url }}">{{a.uid}}</a>{% if not forloop.last %},{% endif %}
                {% endfor %}
            </td>
            <td>{{p.log_first.logdate|date:"Y-m-d"}}</td>
            <td>{{p.log_last.logdate|date:"Y-m-d"}}</td>
            <td>{{p.total_duration}}</td>
            <td>{{p.total_am_time}}</td>
            <td>{{p.total_amhold_time}}</td>
            <td>{{p.last_am_time}}</td>
            <td>{{p.last_amhold_time}}</td>
            <td>{{p.mbox_age|default_if_none:"-"}}</td>
            {% if visitor.is_am %}
            <td>
              {% if p.mbox_stats %}
              <a href="{% url 'display_mail_archive' key=p.lookup_key %}">
                <span class="mbox_sparkline" values="{{p.mbox_stats|join:","}}"></span>
              </a>
              {% else %}
              ---
              {% endif %}
            </td>
            <td>
                {% if p.log_last.logtext %}
                {{ p.log_last.logtext }}
                {% else %}
                [{{p.log_last.progress|sdesc_progress}}]
                {% endif %}
            </td>
            {% endif %}
        </tr>
        {% endfor %}
    </tbody>
</table>


{% endblock %}

